﻿namespace Archie.Retail.Data.SqliteStorage
{
    internal static class DataMapper
    {
        public static Door FromData(ArchieRetailContext ctx, Data.Door door)
        {
            return new Door(door.Id, door.Article, door.Image, ctx.DoorManufacturers.Find(door.DoorManufacturerId), ctx.DoorSeries.Find(door.DoorSeriesId));
        }

        public static DoorManufacturer FromData(Data.DoorManufacturer doorManufacturer)
        {
            return new DoorManufacturer(doorManufacturer.Id, doorManufacturer.Name);
        }

        public static DoorSeries FromData(Data.DoorSeries doorSeries)
        {
            return new DoorSeries(doorSeries.Id, doorSeries.Name);
        }

        public static Handle FromData(ArchieRetailContext ctx, Data.Handle handle)
        {
            return new Handle(handle.Id, handle.Article, handle.Image, ctx.HandleSeries.Find(handle.HandleSeriesId));
        }

        public static HandleSeries FromData(Data.HandleSeries handleSeries)
        {
            return new HandleSeries(handleSeries.Id, handleSeries.Name);
        }

        //************************//

        public static Data.Door ToData(Door door)
        {
            return new Data.Door(door.Id, door.Article, door.Image, ToData(door.DoorManufacturer).Id, ToData(door.DoorSeries).Id);
        }

        public static Data.DoorManufacturer ToData(DoorManufacturer doorManufacturer)
        {
            return new Data.DoorManufacturer(doorManufacturer.Id, doorManufacturer.Name);
        }

        public static Data.DoorSeries ToData(DoorSeries doorSeries)
        {
            return new Data.DoorSeries(doorSeries.Id, doorSeries.Name);
        }

        public static Data.Handle ToData(Handle handle)
        {
            return new Data.Handle(handle.Id, handle.Article, handle.Image, ToData(handle.HandleSeries).Id);
        }

        public static Data.HandleSeries ToData(HandleSeries handleSeries)
        {
            return new Data.HandleSeries(handleSeries.Id, handleSeries.Name);
        }
    }
}